package com.hhj.sharding.sphere.demo.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.hhj.sharding.sphere.demo.serializer.Long2StringSerializer;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @author HHJ
 * @since 2024-05-20
 */
@Data
@TableName("t_order")
public class Order implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 不要使用数据库自增去生成ID, 即使你使用了，插入数据后，也获取到的ID也不是数据库自增的ID
     * 因为已经被Sharding Sphere代理了, 获取到的ID也是Sharding Sphere生成的ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @JsonSerialize(using = Long2StringSerializer.class)
    private Long id;

    /**
     * 用户ID
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 订单ID
     */
    @TableField("order_id")
    private Long orderId;

    /**
     * 订单条目ID
     */
    @TableField("order_item_id")
    private Long orderItemId;

    /**
     * 测试Sharding Sphere使用雪花算法生成唯一值
     */
    @TableField("test_snowflake")
    private Long testSnowflake;

    @TableField("snow_code")
    private String snowCode;

    @TableField("create_time")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @TableField("is_deleted")
    private Integer isDeleted;
}
